package com.xuan.task.Mapper;

import com.xuan.task.domain.ElectronicBookPracticeResult;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ElectronicBookPracticeResultMapper {

    //删除所有记录
    @Delete( "truncate  electronic_book_practice_result " )
    void deleteAll();

    //插入
    @Insert( " insert into electronic_book_practice_result (book_num,user_id,percent_complete,practice_word_count,write_percent_complete," +
            "  recite_percent_complete,read_percent_complete,chose_percent_complete,create_time)" +
            "  values (#{book_num},#{user_id},#{percent_complete},#{practice_word_count},#{write_percent_complete}," +
            "  #{recite_percent_complete},#{read_percent_complete},#{chose_percent_complete},NOW())" )
    void insert(ElectronicBookPracticeResult electronicBookPracticeResult);


    //修改
    @Update( " update electronic_book_practice_result " +
            "  set percent_complete=#{percent_complete},practice_word_count=#{practice_word_count},write_percent_complete=#{write_percent_complete}," +
            "  recite_percent_complete=#{recite_percent_complete},read_percent_complete=#{read_percent_complete},chose_percent_complete=#{chose_percent_complete},create_time=NOW()" +
            "  where user_id=#{user_id} and book_num=#{book_num}" )
    void update(ElectronicBookPracticeResult result);

    //获取用户电子书数据
    @Select( " select * from electronic_book_practice_result" +
            "  where user_id=#{userId} and book_num=#{bookNum} order by create_time desc limit 0,1" )
    ElectronicBookPracticeResult getByUserIdAndBookNum(@Param( "userId" ) String userId, @Param( "bookNum" )String bookNum);


}
